<template>
    <div class="card" @click="toggleCard">
      <div class="card-front" v-if="isFront">
        <div class="card-top">
          <span class="rank">{{ rank }}</span>
          <span class="suit">{{ suit }}</span>
        </div>
        <div class="card-middle"></div>
        <div class="card-bottom">
          <span class="rank">{{ rank }}</span>
          <span class="suit">{{ suit }}</span>
        </div>
      </div>
      <div class="card-back" v-else>
        <div class="card-back-content">
          <!-- 扑克牌背面图案（这里可以自行添加合适的样式或图片等装饰） -->
        </div>
      </div>
    </div>
  </template>
  
  <script>
  export default {
    name: "PlayingCard",
    data() {
      return {
        rank: "A",
        suit: "♣",
        isFront: true // 新增属性，用于控制显示正面还是反面，初始为正面
      };
    },
    methods: {
      toggleCard() {
        this.isFront =!this.isFront; // 点击时切换正反状态
      }
    }
  };
  </script>
  
  <style scoped>
  .card {
    width: 100px;
    height: 150px;
    border: 1px solid black;
    border-radius: 10px;
    background-color: white;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 5px;
    position: relative;
    cursor: pointer; 
     /* 添加鼠标指针样式，提示可点击 */
  }
  
  .card-front,
  .card-back {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 5px;
    backface-visibility: hidden; 
     /* 隐藏背面元素，避免翻转时看到背面内容的闪烁等问题 */
    transition: transform 5s; 
     /* 添加过渡效果，让翻转更平滑 */
  }
  
  .card-front {
    z-index: 2;
  }
  
  .card-back {
    transform: rotateY(180deg); 
     /* 初始将背面旋转180度，隐藏起来 */
    z-index: 1;
    background-color: #ccc; /* 简单设置背面背景色，可替换成合适的背景图等 */
  }
  
  .card-back-content {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    font-weight: bold;
  }
  
  .card-top,
  .card-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  
  .rank {
    font-size: 24px;
    font-weight: bold;
  }
  
  .suit {
    font-size: 30px;
  }
  </style>